module.exports = {
    post: function(req, res) {
        var tablename = "userslist";
        var app = this;
        // console.log(req.params, req.models);
        console.log("（登陆）查询表“", tablename, "”的数据", req.body, req.query);
        var crypto = require('crypto');

        var finner = req.models[tablename].find({
            'username': req.body.username,
            'pwd': crypto.createHash('md5').update(req.body.password).digest('hex')
        });

        finner.run(function(err, result) {
            if (err) {
                res.send(500, err);
            } else if (!result.length) {
                res.send(404, "no found!");
            } else {
                var result = result[0];
                var _hash = Math.random().toString(16).substr(2);
                app.set(_hash, result);
                // console.log(_hash, result);
                //两小时过期
                // var time = 5*1000;
                var time = 2 * 60 * 60 * 1000;
                setTimeout(function() {
                    //清空指定内存区
                    app.set(_hash, null);
                }, time);
                res.cookie("dotnarloginer", _hash, {
                    maxAge: time
                });
                res.cookie("dotnarloginer_username", encodeURI(result.s_name), {
                    maxAge: time
                });
                res.send(result);
            }
        });
    }
}